home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 41 / Amiga Format CD41 (1999-06)(Future Publishing)(GB)[!][issue 1999-07].iso / -seriously_amiga- / programming / other / scrollingtricks / source / scroller_yunlimited2 / hardware.c < prev    next >
C/C++ Source or Header  |  1999-04-19  |  4KB  |  231 lines

  1. #include <exec/exec.h>
  2. #include <dos/dos.h>
  3. #include <intuition/intuition.h>
  4. #include <graphics/gfx.h>
  5. #include <graphics/gfxbase.h>
  6. #include <devices/input.h>
  7. #include <hardware/custom.h>
  8. #include <hardware/dmabits.h>
  9.  
  10. #ifdef __MAXON__
  11. #include <pragma/exec_lib.h>
  12. #include <pragma/dos_lib.h>
  13. #include <pragma/graphics_lib.h>
  14. #include <pragma/intuition_lib.h>
  15. #else
  16. #include <proto/exec.h>
  17. #include <proto/dos.h>
  18. #include <proto/graphics.h>
  19. #include <proto/intuition.h>
  20. #endif
  21.  
  22. #include "hardware.h"
  23.  
  24. static UWORD old_dmacon;
  25. static UWORD old_intena;
  26. static UWORD old_adkcon;
  27. static UWORD old_intreq;
  28.  
  29. static struct MsgPort *inputmp;
  30. static struct IOStdReq *inputreq;
  31. static struct Interrupt inputhandler;
  32. static BOOL    inputdeviceok;
  33.  
  34. static struct View    *oldview;
  35. static struct Window *old_processwinptr;
  36. static struct Process *thisprocess;
  37.  
  38. extern struct IntuitionBase *IntuitionBase;
  39. extern struct GfxBase *GfxBase;
  40.  
  41. static LONG NullInputHandler(void)
  42. {
  43.     // kills all input
  44.     return 0;
  45. }
  46.  
  47. void KillSystem(void)
  48. {
  49.     thisprocess = (struct Process *)FindTask(0);
  50.  
  51.     // safe actual view and install null view
  52.  
  53.     oldview = GfxBase->ActiView;
  54.     
  55.     LoadView(0);
  56.     WaitTOF();
  57.     WaitTOF();
  58.  
  59.     // install NullInputHandler to kill all input events
  60.     
  61.     if ((inputmp = CreateMsgPort()))
  62.     {
  63.         if ((inputreq = CreateIORequest(inputmp,sizeof(*inputreq))))
  64.         {
  65.             if (OpenDevice("input.device",0,(struct IORequest *)inputreq,0) == 0)
  66.             {
  67.                 inputdeviceok = TRUE;
  68.                 
  69.                 inputhandler.is_Node.ln_Type = NT_INTERRUPT;
  70.                 inputhandler.is_Node.ln_Pri = 127;
  71.                 inputhandler.is_Data = 0;
  72.                 inputhandler.is_Code = (APTR)NullInputHandler;
  73.             
  74.                 inputreq->io_Command = IND_ADDHANDLER;
  75.                 inputreq->io_Data = &inputhandler;
  76.                 
  77.                 DoIO((struct IORequest *)inputreq);
  78.             }
  79.         }
  80.     }
  81.     
  82.     // disable requesters for our process
  83.     
  84.     old_processwinptr = thisprocess->pr_WindowPtr;
  85.     thisprocess->pr_WindowPtr = (APTR)-1;
  86.  
  87.     // lock blitter
  88.  
  89.     OwnBlitter();
  90.     WaitBlit();
  91.     
  92.     // no multitasking/interrupts
  93.  
  94.     Disable();
  95.  
  96.     // save important custom registers
  97.     
  98.     old_dmacon = custom->dmaconr | 0x8000;
  99.     old_intena = custom->intenar | 0x8000;
  100.     old_adkcon = custom->adkconr | 0x8000;
  101.     old_intreq = custom->intreqr | 0x8000;
  102.  
  103. }
  104.  
  105. void ActivateSystem(void)
  106. {
  107.     // reset important custom registers
  108.     
  109.     custom->dmacon = 0x7FFF;
  110.     custom->intena = 0x7FFF;
  111.     custom->adkcon = 0x7FFF;
  112.     custom->intreq = 0x7FFF;
  113.  
  114.     custom->dmacon = old_dmacon;
  115.     custom->intena = old_intena;
  116.     custom->adkcon = old_adkcon;
  117.     custom->intreq = old_intreq;
  118.  
  119.     // enable multitasking/interrupts
  120.  
  121.     Enable();
  122.  
  123.     // unlock blitter
  124.  
  125.     WaitBlit();
  126.     DisownBlitter();
  127.  
  128.     // enable requesters for our process
  129.     
  130.     thisprocess->pr_WindowPtr = old_processwinptr;
  131.  
  132.     // remove null inputhandler
  133.     
  134.     if (inputdeviceok)
  135.     {
  136.         inputreq->io_Command = IND_REMHANDLER;
  137.         inputreq->io_Data = &inputhandler;
  138.         DoIO((struct IORequest *)inputreq);
  139.         
  140.         CloseDevice((struct IORequest *)inputreq);
  141.     }
  142.  
  143.     if (inputreq) DeleteIORequest(inputreq);
  144.     if (inputmp) DeleteMsgPort(inputmp);
  145.  
  146.     // reset old view
  147.  
  148.     LoadView(oldview);
  149.     WaitTOF();
  150.     WaitTOF();    
  151. }
  152.  
  153. void WaitVBL(void)
  154. {
  155.     UBYTE b;
  156.     
  157.     b = *(UBYTE *)0xbfe801;
  158.     
  159.     while(*(UBYTE *)0xbfe801 == b)
  160.     {
  161.     }
  162. }
  163.  
  164. void WaitVBeam(ULONG line)
  165. {
  166.     ULONG vpos;
  167.  
  168.     line *= 0x100;
  169.  
  170.     do {
  171.             vpos = *(ULONG *)0xdff004;
  172.     } while ((vpos & 0x1FF00) != line);
  173.  
  174. }
  175.  
  176. void HardWaitBlit(void)
  177. {
  178.     if (custom->dmaconr & DMAF_BLTDONE)
  179.     {
  180.     }
  181.  
  182.     while (custom->dmaconr & DMAF_BLTDONE)
  183.     {
  184.     }
  185. }
  186.  
  187. void HardWaitLMB(void)
  188. {
  189.     while (((*(UBYTE *)0xbfe001) & 64) != 0)
  190.     {
  191.     }
  192.  
  193.     while (((*(UBYTE *)0xbfe001) & 64) == 0)
  194.     {
  195.     }
  196.  
  197. }
  198.  
  199. BOOL JoyUp(void)
  200. {
  201.     // ^ = xor
  202.  
  203.     WORD w;
  204.     
  205.     w = custom->joy1dat << 1;
  206.  
  207.     return ((w ^ custom->joy1dat) & 512) ? TRUE : FALSE;
  208. }
  209.  
  210. BOOL JoyDown(void)
  211. {
  212.     // ^ = xor
  213.  
  214.     WORD w;
  215.     
  216.     w = custom->joy1dat << 1;
  217.  
  218.     return ((w ^ custom->joy1dat) & 2) ? TRUE : FALSE;
  219. }
  220.  
  221. BOOL JoyFire(void)
  222. {
  223.     return ((*(UBYTE *)0xbfe001) & 128) ? FALSE : TRUE;
  224. }
  225.  
  226. BOOL LMBDown(void)
  227. {
  228.     return ((*(UBYTE *)0xbfe001) & 64) ? FALSE : TRUE;
  229. }
  230.  
  231.